package com.bbcare.followup.plat.controller.fd;

import com.bbcare.comm.ResultModel;
import com.bbcare.followup.plat.entity.DumpMessageRecord;
import com.bbcare.followup.plat.service.IDumpMessageRecordService;
import com.bbcare.followup.plat.service.IDumpPlanUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 复旦儿科患者消息记录Controller
 *
 * @author gxl
 * @date 2020-11-03
 */
@RestController
@RequestMapping("/webapi/service/DumpMessageRecord")
public class DumpMessageRecordController {
    @Autowired
    private IDumpMessageRecordService dumpMessageRecordService;
    @Autowired
    private IDumpPlanUploadService dumpPlanUploadService;
    /**
     * 查询复旦儿科患者消息记录列表
     */

    @PostMapping("/list")
    public ResultModel<Map<String, Object>> list(@RequestBody Map params) {
        Map map = new HashMap();
        Integer currentPage = Integer.parseInt(params.get("currentPage").toString());
        Integer pageSize = Integer.parseInt(params.get("pageSize").toString());
        params.put("start",pageSize*currentPage);
        params.put("end",pageSize*(currentPage-1));
        List<DumpMessageRecord> list = dumpMessageRecordService.selectDumpMessageRecordList(params);
        Integer total = dumpMessageRecordService.selectCountDumpMessageRecord(params);
        map.put("data", list);
        map.put("count",total);
        return new ResultModel(map);
    }



    /**
     * 获取复旦儿科患者消息记录详细信息
     */

    @PostMapping(value = "/getInfo")
    public ResultModel<Map<String, Object>> getInfo(@RequestBody Map param) {
        return new ResultModel(dumpMessageRecordService.selectDumpMessageRecordById(param.get("id").toString()));
    }

    /**
     * 新增复旦儿科患者消息记录
     */

    @PostMapping(value = "/add")
    public ResultModel<Map<String, Object>> add(@RequestBody DumpMessageRecord DumpMessageRecord) {
        dumpMessageRecordService.insertDumpMessageRecord(DumpMessageRecord);
        return new ResultModel("添加成功");
    }

    /**
     * 修改复旦儿科患者消息记录
     */

    @PostMapping(value = "update")
    public ResultModel<Map<String, Object>> edit(@RequestBody DumpMessageRecord DumpMessageRecord) {
        dumpMessageRecordService.updateDumpMessageRecord(DumpMessageRecord);
        return new ResultModel("修改成功");
    }

    /**
     * 删除复旦儿科患者消息记录
     */
    @PostMapping("/delete")
    public ResultModel<Map<String, Object>> remove(@RequestBody String[] ids) {
        dumpMessageRecordService.deleteDumpMessageRecordByIds(ids);
        return new ResultModel("删除成功");
    }

    /**
     * 患者消息已读通知
     */
    @PostMapping("/receipt")
    public ResultModel<Map<String, Object>> receipt(@RequestBody Map params) {
        params.put("completeTime",new Date());
        dumpMessageRecordService.receiptDumpMessageRecord(params);
        String url = dumpPlanUploadService.selectDumpPlanUploadById(params.get("dumpPlanId").toString()).getUrl();
        Map<String, Object> map = new HashMap<>();
        map.put("url",url);
        return new ResultModel(map);
    }
}
